package com.zhuzi.dto.ths;

import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.select.Elements;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author zhuzi
 * 2022/8/2 07:51
 * 同花顺-新闻列表li
 */

@Data
@Accessors(chain = true)
public class ThsNews implements Serializable {
    private Long id;
    /**
     * 标题
     */
    private String title;
    private String gn;
    /**
     * url
     */
    private String url;
    /**
     * 发布时间
     */
    private LocalDateTime publishTime;

    /**
     * 正股名称
     */
    private String stockNm;
    /**
     * 正股代码
     */
    private String stockId;

    private String newContent;

    public ThsNews(String title, String url) {
        this.title = title;
        this.url = url;
        this.id = Long.parseLong(StringUtils.substringBetween(url, "/c", ".shtml"));
    }

    public ThsNews setUrl(String url) {
        this.url = url;
        //http://news.10jqka.com.cn/20220801/c640829742.shtml
        this.id = Long.parseLong(StringUtils.substringBetween(url, "/c", ".shtml"));
        return this;
    }

    public void parseStock(Elements ele) {
        this.stockNm = ele.select("a:nth-last-child(2)").text();
        this.stockId = ele.select("a:last-child").text();
    }
}
